﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CopsBanditsUI {
    import flash.events.*;
    import flash.display.*;
    import Events.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import flash.filters.*;
    import Modules.bandits.*;
    import Display.*;
    import Display.ValentineUI.*;
    import org.aswing.event.*;
    import Display.aswingui.*;
    import L10n.*;
    import Modules.bandits.transactions.*;

    public class OfficersPanel extends JPanel {

        public var m_officers:OfficersScrollingList;
        protected var m_buyButton:JButton;
        protected var m_getDonutsButton:JButton;

        public function OfficersPanel(){
            super(new FlowLayout(FlowLayout.LEFT));
            this.init();
        }
        protected function init():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -15);
            var _local2:DisplayObject = (new (CopsDialog.assetDict["inner_undertab"])() as DisplayObject);
            this.setBackgroundDecorator(new AssetBackground(_local2));
            this.createListContent();
            this.addEventListener(UIEvent.BUY_DONUT, this.toggleBuyButton, false, 0, true);
            _local1.append(this.m_officers);
            _local1.append(this.makeButtonsPanel());
            this.append(_local1);
            this.setPreferredWidth(671);
            this.setPreferredHeight(390);
            this.setlocalizationforAllComponents();
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        protected function createListContent():void{
            this.m_officers = new OfficersScrollingList();
        }
        protected function updateCell(_arg1:int, _arg2:String, _arg3:Boolean=false):void{
            this.m_officers.updateCell(_arg1, _arg2, _arg3);
        }
        protected function makeButtonsPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER, 10);
            var _local2:AssetIcon = new AssetIcon((new EmbeddedArt.icon_cash() as DisplayObject));
            this.m_buyButton = new CustomButton("", _local2, "CashButtonUI");
            this.m_buyButton.setMargin(new Insets(3, 10, 3, 10));
            this.m_buyButton.setFont(new ASFont(EmbeddedArt.TITLE_FONT, 16, false, false, false, EmbeddedArt.advancedFontProps));
            this.m_buyButton.setTextFilters([new DropShadowFilter(1, 90, 0, 0.2, 3, 3, 3, 1), new GlowFilter(0, 0.2, 4, 4, 10)]);
            this.m_getDonutsButton = new CustomButton("", null, "GreenButtonUI");
            this.m_getDonutsButton.setFont(new ASFont(EmbeddedArt.TITLE_FONT, 16, false, false, false, EmbeddedArt.advancedFontProps));
            this.m_getDonutsButton.setMargin(new Insets(5, 10, 5, 10));
            this.judgeButtonEnable();
            this.m_buyButton.addActionListener(this.buyDonuts, 0, true);
            this.m_getDonutsButton.addActionListener(this.sendDonutsFeed, 0, true);
            _local1.appendAll(this.m_buyButton, this.m_getDonutsButton);
            return (_local1);
        }
        protected function judgeButtonEnable():void{
            var _local1:int = BanditManager.findDonutHungryCop();
            if (_local1 == -1){
                this.m_buyButton.setEnabled(false);
                this.m_getDonutsButton.setEnabled(false);
            };
        }
        protected function setlocalizationforAllComponents():void{
            var _local1:String = ZLoc.t("Dialogs", "Cops_button_xfordonut", {amount:String(5)});
            if (!LocaleHelper.localSetting.sns.cash_enable){
                ZLoc.t("Dialogs", "Cops_button_xfordonut", {amount:"???"});
            };
            this.m_buyButton.setText(_local1);
            _local1 = ZLoc.t("Dialogs", "Cops_button_getdonuts");
            this.m_getDonutsButton.setText(_local1);
        }
        protected function toggleBuyButton(_arg1:Event=null):void{
            var _local2:int = BanditManager.findDonutHungryCop();
            if (_local2 == -1){
                this.m_buyButton.setEnabled(false);
                this.m_getDonutsButton.setEnabled(false);
            } else {
                this.m_buyButton.setEnabled(true);
                this.m_getDonutsButton.setEnabled(true);
            };
            ASwingHelper.prepare(this.parent);
        }
        protected function buyDonuts(_arg1:AWEvent):void{
            var _local3:int;
            var _local4:String;
            var _local2:int = BanditManager.findDonutHungryCop();
            if (_local2 != -1){
                _local3 = Global.gameSettings.getInt("CNBdonutCashCost", 5);
                if (Global.player.cash >= _local3){
                    Global.player.cash = (Global.player.cash - _local3);
                    _local4 = BanditManager.giveDonutAndWake(_local2);
                    UI.requestPatrol(null, null, _local2);
                    GameTransactionManager.addTransaction(new TBuyDonut(_local2));
                    this.updateCell(_local2, _local4, true);
                    this.toggleBuyButton();
                    BanditUtil.logDialogStats("buy_donut", "station_ui");
                    BanditUtil.refreshPoliceStationAppearance();
                } else {
                    UI.displayPopup(new GetCoinsDialog(ZLoc.t("Dialogs", "ImpulseMarketCash"), "GetCash", GenericDialogView.TYPE_GETCASH, null, true));
                };
            };
        }
        protected function sendDonutsFeed(_arg1:AWEvent):void{
            var _local2:Boolean = Global.world.viralMgr.sendGetDonut();
            if (!_local2){
                UI.displayMessage(ZLoc.t("Dialogs", "Cops_feedMax"), GenericDialogView.TYPE_OK);
                BanditUtil.logDialogStats("view", "request_limit_ui");
            } else {
                BanditUtil.refreshPoliceStationAppearance();
                BanditUtil.logDialogStats("get_donut", "station_ui");
            };
        }

    }
}//package Display.CopsBanditsUI 
